20B - Equation - CodeForces Solution


math *2000

Please click on ads to support us..

Python Code:

a,b,c=list(map(int,input().split()))
if a==0 and b==0 and c==0:
    print(-1)
elif a==0 and b==0:
    print(0)
elif a==0 and c==0:
    print(1)
    print(0)
elif b==0 and c==0:
    print(1)
    print(0)
elif a==0:
    print(1)
    print(-c/b)
else:
    if (b**2)-(4*a*c)>0:
        print(2)
        print(min((-b-((b**2)-(4*a*c))**0.5)/(2*a),(-b+((b**2)-(4*a*c))**0.5)/(2*a)))
        print(max((-b-((b**2)-(4*a*c))**0.5)/(2*a),(-b+((b**2)-(4*a*c))**0.5)/(2*a)))
    elif (b**2)-(4*a*c)==0:
        print(1)
        print(-b/(2*a))
    else:
        print(0)

C++ Code:

#include <bits/stdc++.h>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
//typedef double db;
#define ss second
#define ff first
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vll vector<pll>
#define vd vector<db>
#define pdd  pair<db,db>
#define vdd  vector<pdd>
#define mll map <ll,ll>
#define sl set <ll>
#define sll set <pll>
#define f(i,j,k,l) for(ll i=j;i<k;i+=l)
#define fj(j,m) for(auto j=m.begin();j!=m.end();j++)
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl "\n"
const db pi=3.14159265359;
const int mod = 1e9+7;
const db EPS = 0.000000001; // 1 e -9
const ll inf = (ll)1e18;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}

int run_case()
{
    ll  r,k,u,p,i,n,h,y,z,l,e,q,w,x,j;
    cin >> k >> n >> x ;
    cout << setprecision(5) << fixed;
    if (k==0)
    {
        if (n==0)
        {
            if (x==0)
            {
                cout << -1 << endl;
            }
            else
            {
                cout << 0 << endl;
            }
        }
        else
        {
            cout << 1 << endl;
            cout << -(db)x/(db)n << endl;
        }
    }
    else
    {
        p=n*n-4*k*x;
        if (p>0)
        {
            cout << 2 << endl;
            cout << min((-(db)n-sqrt(p))/(2.0*k),(-(db)n+sqrt(p))/(2.0*k)) << endl;
            cout << max((-(db)n+sqrt(p))/(2.0*k),(-(db)n-sqrt(p))/(2.0*k)) << endl;
        }
        else if (p==0)
        {
            cout << 1 << endl;
            cout << -(db)n/(2.0*k) << endl;
        }
        else
        {
            cout << 0 << endl;
        }
    }

return 0;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t = 1;//cin >> t;
    while(t--){
        run_case();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces
711A - Bus to Udayland
779B - Weird Rounding
1703D - Double Strings
1704C - Virus
63A - Sinking Ship
1704B - Luke is a Foodie
298B - Sail
239A - Two Bags of Potatoes
1704E - Count Seconds
682A - Alyona and Numbers
44A - Indian Summer
1133C - Balanced Team
1704A - Two 0-1 Sequences
1467A - Wizard of Orz
1714E - Add Modulo 10
1714A - Everyone Loves to Sleep